package com.idemon.ds.util;

import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Enumeration;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.log4j.Logger;

import com.mysql.jdbc.AbandonedConnectionCleanupThread;

public class CleanupListener implements ServletContextListener {
	private Logger log = Logger.getLogger(getClass());

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		final Enumeration<Driver> drivers = DriverManager.getDrivers();
		while (drivers.hasMoreElements()) {
			try {
				final Driver driver = drivers.nextElement();
				DriverManager.deregisterDriver(driver);
			} catch (final SQLException e) {
				log.error("clean up error", e);
			}
		}
		AbandonedConnectionCleanupThread.uncheckedShutdown();
	}

}
